#include"..\..\Public\Windows\WindowsPlatformMisc.h"
#include"..\..\Public/Windows/WindowsHWrapper.h"
//hzc add header
#include<malloc.h>



int32 FWindowsPlatformMisc::NumberOfCores()
{
	static int32 CoreCount = 0;


	// Get only physical cores
	PSYSTEM_LOGICAL_PROCESSOR_INFORMATION InfoBuffer = NULL;
	::DWORD BufferSize = 0;

	// Get the size of the buffer to hold processor information.
	::BOOL Result = GetLogicalProcessorInformation(InfoBuffer, &BufferSize);
	//check(!Result && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
	//check(BufferSize > 0);

	// Allocate the buffer to hold the processor info.
	InfoBuffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(BufferSize);//FMemory::Malloc(BufferSize);
	//check(InfoBuffer);

	// Get the actual information.
	Result = GetLogicalProcessorInformation(InfoBuffer, &BufferSize);
	//check(Result);

	// Count physical cores
	const int32 InfoCount = (int32)(BufferSize / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
	for (int32 Index = 0; Index < InfoCount; ++Index)
	{
		SYSTEM_LOGICAL_PROCESSOR_INFORMATION* Info = &InfoBuffer[Index];
		if (Info->Relationship == RelationProcessorCore)
		{
			CoreCount++;
		}
	}
	free(InfoBuffer);//FMemory::Free(InfoBuffer);


	return CoreCount;
}